<template>
  <view class="mine-container" :style="{height: `${windowHeight}px`}">
    <!--顶部个人信息栏-->
    <view class="header-section">
      <!-- 获取用户头像 -->
      <button class="avatar-wrapper" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
      	<image class="avatar" :src="avatar"></image>
      </button>
      <view class="flex justify-center align-center">
        <view class="user-info">
          <view class="u_title">
            昵称：{{ nickName }}
          </view>
        </view>
      </view>
    </view>

    <view class="content-section">
      <view class="mine-actions grid col-4 text-center">
        <view class="action-item" @click="handleJiaoLiuQun">
          <view class="iconfont icon-friendfill text-pink icon"></view>
          <text class="text">交流群</text>
        </view>
        <view class="action-item" @click="handleBuilding">
          <view class="iconfont icon-service text-blue icon"></view>
          <text class="text">在线客服</text>
        </view>
        <view class="action-item" @click="handleBuilding">
          <view class="iconfont icon-community text-mauve icon"></view>
          <text class="text">反馈社区</text>
        </view>
        <view class="action-item" @click="handleBuilding">
          <view class="iconfont icon-dianzan text-green icon"></view>
          <text class="text">点赞我们</text>
        </view>
      </view>

      <view class="menu-list">
        <view class="list-cell list-cell-arrow" @click="handleToEditInfo">
          <view class="menu-item-box">
            <view class="iconfont icon-user menu-icon"></view>
            <view>编辑资料</view>
          </view>
        </view>
        <view class="list-cell list-cell-arrow" @click="handleHelp">
          <view class="menu-item-box">
            <view class="iconfont icon-help menu-icon"></view>
            <view>常见问题</view>
          </view>
        </view>
        <view class="list-cell list-cell-arrow" @click="handleAbout">
          <view class="menu-item-box">
            <view class="iconfont icon-aixin menu-icon"></view>
            <view>关于我们</view>
          </view>
        </view>
        <view class="list-cell list-cell-arrow" @click="handleToSetting">
          <view class="menu-item-box">
            <view class="iconfont icon-setting menu-icon"></view>
            <view>应用设置</view>
          </view>
        </view>
      </view>

    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        windowHeight: uni.getSystemInfoSync().windowHeight,
        nickName: '',
				avatar:''
      }
    },
		onShow() {
			this.$request({
        url:'/getInfo'
      }).then(res => {
        this.nickName = res.data.name
				this.$request({
					url:'/minio/preview?fileName=' + res.data.avatar
				}).then(response => {
					this.avatar = response.data
				})
      }).catch(() => {
        
      })   
    },
    methods: {
      onChooseAvatar(e) {
        console.log('微信头像信息', e)
        // 将数据赋值
        const { avatarUrl } = e.detail 
        this.avatar = avatarUrl
        // this.$store.state.baseUserInfo.avatarUrl = avatarUrl
        uni.uploadFile({
          url: this.$BASE_URL + '/avatar',
          name: 'avatarFile',
          filePath: avatarUrl,
          header: {'Authorization':this.$store.state.token},
          success: response => {
            uni.showToast({ title: "上传成功", icon: 'success' })
          }
        })
      },
      handleToEditInfo() {
        uni.navigateTo({
					url:'/pages/mine/info/edit'
				})
      },
      handleToSetting() {
        uni.navigateTo({
					url:'/pages/mine/setting/index'
				})
      },
      handleHelp() {
        uni.navigateTo({
					url:'/pages/mine/help/index'
				})
      },
      handleAbout() {
        uni.navigateTo({
					url:'/pages/mine/about/index'
				})
      },
      handleJiaoLiuQun() {
        uni.showToast({
					icon: 'none',
					title:'QQ群258888888'
				})
      },
      handleBuilding() {
        uni.showToast({
        	icon: 'none',
        	title:'模块建设中'
        })
      }
    }
  }
</script>

<style lang="scss">
  page {
    background-color: #f5f6f7;
  }

  .mine-container {
    width: 100%;
    height: 100%;


    .header-section {
      padding: 15px 15px 45px 15px;
      background-color: #3c96f3;
      color: white;

      .login-tip {
        font-size: 18px;
        margin-left: 10px;
      }

      .user-info {
        .u_title {
          font-size: 18px;
          line-height: 30px;
        }
      }
    }

    .content-section {
      position: relative;

      .mine-actions {
        margin: 15px 15px;
        padding: 20px 0px;
        border-radius: 8px;
        background-color: white;

        .action-item {
          .icon {
            font-size: 28px;
          }

          .text {
            display: block;
            font-size: 13px;
            margin: 8px 0px;
          }
        }
      }
    }
  }

  .avatar-wrapper{
    width: 120rpx;
    height: 120rpx;
    border-radius: 30px;
    margin-bottom: 10px;
  }
  .avatar{
    position:absolute;
    width: 120rpx;
    height: 120rpx;
    left: 0%;
    z-index: 1;
  }

</style>
